import org.molamil.acto.core.CategorizedListener;

/**
 * @author Jorge Hernandez
 */
class org.molamil.acto.core.CategorizedListeners {
	
	
	// Properties
	
	private var list:Array;
	
	
	// Constructor 
	
	public function CategorizedListeners() {
		list = new Array();
	}
	
	public function addListener(category:String, event:String, handler):Void {
		if (!existsListener(category, event, handler))
			list.push(new CategorizedListener(category, event, handler));
	}

	public function removeListener(category:String, event:String, handler):Void {
		var a:Array = new Array();
		for (var i:Number = 0; i < list.length; i++) {
			var cl:CategorizedListener = list[i];
			if (cl.category != category || cl.event != event || cl.handler != handler)
				a.push(list[i]);
		}
		list = a;
	}
	
	public function existsListener(category:String, event:String, handler):Boolean {
		var b:Boolean = false;
		for (var i:Number = 0; i < list.length; i++) {
			var cl:CategorizedListener = list[i];
			if (cl.category == category && cl.event == event && cl.handler == handler) {
				b = true;
				break;
			}
		}
		return b;
	}
	
	public function getListeners(category:String, event:String):Array {
		var a:Array = new Array();
		for (var i:Number = 0; i < list.length; i++) {
			var cl:CategorizedListener = list[i];
			if (cl.category == category && cl.event == event)
				a.push(cl);
		}
		return a;
	}
	
	
}
